package ru.payment.wm.impl;

import org.dom4j.Element;
import ru.payment.wm.Trust;

/**
 *
 * User: sergey
 * Date: 23.04.2009
 * Time: 17:15:15
 *
 */
public class TrustParser extends AbstractResponseParser<Trust, Element> {

  public void parse(Element e, Trust t) throws ProtocolException {

    if (e == null) {
      return;
    }

    t.setTrustId(attrAsString(e.attribute("id"), ""));
    t.setAllowInvoice(attrAsBoolean(e.attribute("inv"), false));
    t.setAllowTrans(attrAsBoolean(e.attribute("trans"), false));
    t.setAllowPurse(attrAsBoolean(e.attribute("purse"), false));
    t.setAllowTransHist(attrAsBoolean(e.attribute("transhist"), false));

    t.setMaster(asString(e.element("master"), ""));
    t.setPurse(asString(e.element("purse"), ""));

    t.setLimit(asFloat(e.element("daylimit"), 0));
    t.setDayLimit(asFloat(e.element("dlimit"), 0));
    t.setWeekLimit(asFloat(e.element("wlimit"), 0));
    t.setMonthLimit(asFloat(e.element("mlimit"), 0));

    t.setDaySumma(asFloat(e.element("dsum"), 0));
    t.setWeekSumma(asFloat(e.element("wsum"), 0));
    t.setMonthSumma(asFloat(e.element("msum"), 0));

    t.setLastTransferDate(asDate(e.element("lastsumdate"), "yyyy.MM.dd"));
  }

}
